const BaseModel = require('../basemodel.js')

module.exports = class DynamicModel extends BaseModel {

	constructor(_db, _id) {
		super(_db, "lg-company-dynamic", _id)
		this.keywords = "" // 关键字
		this.title = "" // 标题
		this.content = "" // 内容
		this.preview_img = "" // 预览图片
		this.refLink = "" //来源连接
		this.refName = "" //来源
		this.type = ""  // 类型
		this.click_num = 0 //点击次数
		this.hot_num = 0 //热度
		this.sort = 0 // 排序
		this.state = 1 //状态
		this.create_date = "" //创建日期
		this.lastupdate_date = "" //更新日期
	}
	
	//获取热度排名
	async getHotDynamicSort(limit = 3){
	    return	 await  this._collection.orderBy('hot_num','desc').limit(limit).get();
	}
	
	async getIdOfFirstDynamicByType(type = 1){
		return await this._collection.where({type}).orderBy('create_date','desc').limit(1).field({'_id':true}).get()
	}
	
    // 分页获取不同类型动态信息
	async pageDynamicByType({id = "",type=1,limit = 6} = {}){
		let where = {type,'_id':this._dbCmd.gt(id)}
		if(!id){
			where = {type}
		}
		return await this._collection.orderBy('create_date','desc').where(where).limit(limit).get()
	}
}
